package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.knowledgebase.vo.RuleRegulationVo;
import cn.sdormitory.service.AppRuleRegulationService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "app => 规章制度")
@RestController
@RequestMapping("/app/ruleRegulation")
public class AppRuleRegulationController {

    @Autowired
    private AppRuleRegulationService appRuleRegulationService;

    @GetMapping("/ruleRegulationList")
    public CommonResult<List<RuleRegulationVo>> getRuleRegulationList() {
        return CommonResult.success(appRuleRegulationService.getRuleRegulationList());
    }

    @GetMapping("/getRuleRegulationById/{id}")
    public CommonResult getRuleRegulationById(@PathVariable Integer id) {
        return CommonResult.success(appRuleRegulationService.getRuleRegulationById(id));
    }
    @GetMapping("/autoIncrementViewCount/{id}")
    public CommonResult<Integer> autoIncrementViewCount(@PathVariable Integer id) {
        Integer i = appRuleRegulationService.incrementViewCount(id);
        if (i > 0) {
            Integer viewCount = appRuleRegulationService.getViewCount(id);
            return CommonResult.success(viewCount);
        }
        return CommonResult.failed();
    }
}
